package com.cskaoyan.service;

import com.cskaoyan.bean.bo.*;
import com.cskaoyan.bean.pojo.*;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.bean.pojo.Brand;
import com.cskaoyan.bean.pojo.BrandExample;
import com.cskaoyan.bean.pojo.Region;
import com.cskaoyan.bean.pojo.RegionExample;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.dao.*;
import com.cskaoyan.bean.vo.grouponvo.CreatIssueVO;
import com.cskaoyan.bean.vo.grouponvo.KeywordListVO;
import com.cskaoyan.dao.BrandMapper;
import com.cskaoyan.dao.IssueMapper;
import com.cskaoyan.dao.KeywordMapper;
import com.cskaoyan.dao.RegionMapper;
import com.github.pagehelper.Page;
import com.cskaoyan.utils.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.System;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author: hdf、ckd
 * @class: MallServiceImpl
 */
@SuppressWarnings("all")
@Service
@Transactional
public class MallServiceImpl implements MallService {

    @Autowired
    RegionMapper regionMapper;
    @Autowired
    BrandMapper brandMapper;
    @Autowired
    IssueMapper issueMapper;
    @Autowired
    KeywordMapper keywordMapper;
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;



    /**
     * @author: 刘东升
     * @title: queryRegion
     * @description: 查询省市县（区）
     * @param: []
     * @return: java.util.List<com.cskaoyan.bean.vo.MallRegionListVO>
     */
    @Override
    public List<MallRegionListVO> queryRegion() {
        RegionExample regionExample = new RegionExample();
        regionExample.setOrderByClause("code asc");
        RegionExample.Criteria criteria = regionExample.createCriteria();

        List<Region> regions = regionMapper.selectByExample(regionExample);
        LinkedList<MallRegionListVO> mallRegionListVOS = new LinkedList<>();

        for (Region region : regions) {
            Integer code = region.getCode();
            Integer id = region.getId();
            Byte type = region.getType();
            String name = region.getName();
            if (type == 1) {
                MallRegionListVO mallRegionListVO = new MallRegionListVO(id, name, type, code, null);
                mallRegionListVOS.add(mallRegionListVO);
            } else {
                break;
            }
        }

        for (MallRegionListVO mallRegionListVO : mallRegionListVOS) {
            int provinceId = mallRegionListVO.getId();
            LinkedList<RegionVo> regionVOS = new LinkedList<>();
            for (Region region : regions) {
                Integer code = region.getCode();
                Integer id = region.getId();
                Byte type = region.getType();
                String name = region.getName();
                if (type == 2 && region.getPid() == provinceId) {
                    //市
                    RegionVo regionVo = new RegionVo(id, name, (int) type, code, null);
                    LinkedList<RegionVo> regionDistrictVos = new LinkedList<>();
                    for (Region regionDistrict : regions) {
                        Integer regionDistrictId = regionDistrict.getId();
                        Integer regionDistrictCode = regionDistrict.getCode();
                        Byte regionDistrictType = regionDistrict.getType();
                        String regionDistrictName = regionDistrict.getName();
                        if (regionDistrictType == 3 && regionDistrict.getPid() == regionVo.getId()) {
                            RegionVo regionDistrictVo = new RegionVo(regionDistrictId, regionDistrictName, (int) regionDistrictType, regionDistrictCode, null);
                            regionDistrictVos.add(regionDistrictVo);
                        }
                    }
                    regionVo.setChildren(regionDistrictVos);
                    regionVOS.add(regionVo);
                }
            }
            mallRegionListVO.setChildren(regionVOS);
        }

        return mallRegionListVOS;
    }

    /**
     * @author hdf
     * @param page  页码数
     * @param limit 每页行数
     * @param sort  排序字段
     * @param order 排序规则
     * @return mallBrandVO
     * @description 获得品牌制造商list
     */
    @Override
    public MallBrandVO selectByExample(BrandListBO brandListBO) {

        //根据传入的分页要求分页
        PageHelper.startPage(brandListBO.getPage(), brandListBO.getLimit());


        //提供查询Exampleshi实例
        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();

        //根据id精确查询 根据name模糊查询(需要判空)
        if (brandListBO.getId() != null) {
            criteria.andIdEqualTo(brandListBO.getId());
        }
        if (!StringUtils.isEmpty(brandListBO.getName())) {
            criteria.andNameLike("%" + brandListBO.getName() + "%");
        }
        criteria.andDeletedEqualTo(false);
        //根据sort和order 排序
        brandExample.setOrderByClause(brandListBO.getSort() + " " + brandListBO.getOrder());

        //根据设定条件进行查询
        List<Brand> brands = brandMapper.selectByExample(brandExample);

        //分页也会有查询总行数，放在select语句之后
        long total = brandMapper.countByExample(brandExample);

        List<MallBrandListVO> mallBrandListVOS = new ArrayList<>();

        //转换格式
        for (Brand brand : brands) {
            MallBrandListVO mallBrandListVO = new MallBrandListVO(brand.getId(), brand.getName(), brand.getDesc(), brand.getPicUrl(), brand.getSortOrder(), brand.getFloorPrice(), brand.getAddTime(), brand.getUpdateTime(), brand.getDeleted());
            mallBrandListVOS.add(mallBrandListVO);
        }

        MallBrandVO mallBrandVO = new MallBrandVO(total, mallBrandListVOS);

        return mallBrandVO;

    }

    /**
     * @return IssueListVO
     * @author ckd
     * @description 获得通用问题list
     */
    @Override
    public IssueListVO issueList(Integer page, Integer limit, String sort, String order, String question) {
        PageHelper.startPage(page, limit);
        IssueExample issueExample = new IssueExample();
        IssueExample.Criteria criteria = issueExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (question != null) {
            criteria.andQuestionLike("%" + question + "%");
        }
        issueExample.setOrderByClause(sort + " " + order);
        List<ItemsBean> itemsBean = new ArrayList<>();
        List<Issue> issues = issueMapper.selectByExample(issueExample);

        for (Issue issue : issues) {
            itemsBean.add(new ItemsBean(issue.getId(), issue.getQuestion(), issue.getAnswer(),
                    issue.getAddTime(), issue.getUpdateTime(), issue.getDeleted()));
        }
        PageInfo<Issue> issuePageInfo = new PageInfo<>(issues);
        int count = (int) issuePageInfo.getTotal();
        return new IssueListVO(count, itemsBean);
    }


    /**
     * @param record
     * @return 添加的行数
     * @author hdf
     */
    @Override
    public MallBrandCreateVO insertSelective(BrandAddBO brandAddBO) {

        BrandExample brandExample1 = new BrandExample();
        BrandExample.Criteria criteria1 = brandExample1.createCriteria();
        criteria1.andNameEqualTo(brandAddBO.getName());
        List<Brand> brands = brandMapper.selectByExample(brandExample1);
        if (brands.size() != 0){
            return null;
        }

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        int i = 0;
        try {
            Date parse = simpleDateFormat.parse(format);
            Brand brand = new Brand(null, brandAddBO.getName(), brandAddBO.getDesc(), brandAddBO.getPicUrl(), brandAddBO.getFloorPrice(), parse, parse);
            i = brandMapper.insertSelective(brand);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();

        if (!StringUtils.isEmpty(brandAddBO.getPicUrl())) {
            criteria.andPicUrlEqualTo(brandAddBO.getPicUrl());

        }

        List<Brand> brand = brandMapper.selectByExample(brandExample);
        MallBrandCreateVO mallBrandCreateVO = null;
        for (Brand brand1 : brand) {
            mallBrandCreateVO = new MallBrandCreateVO(brand1.getId(), brand1.getName(), brand1.getDesc(), brand1.getPicUrl(), brand1.getFloorPrice(), brand1.getAddTime(), brand1.getUpdateTime());
        }

        return mallBrandCreateVO;
    }

    /*
     * @author hdf
     * @param record
     * @param example
     * @description 修改品牌商信息
     * @return
     */
    @Override
    public Brand updateByExample(Brand brand) {
        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();
        criteria.andIdIsNull();
        int i = brandMapper.updateByExample(brand, brandExample);
        Brand brand1 = brandMapper.selectByPrimaryKey(brand.getId());
        return brand1;
    }

    @Override
    public int updateByExampleSelective(Brand record) {
        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();
        criteria.andIdEqualTo(record.getId());
        record.setDeleted(true);
        int i = brandMapper.updateByExampleSelective(record, brandExample);
        return i;
    }

    /**
     * @return
     * @author hdf
     * @description 查询商品类目
     */
    @Override
    public List<CategoryListVO> selectCategory() {

        //按照pid为0，查询一级类目
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andPidEqualTo(0);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);


        //按照一级类目的id,查询二级类目
        List<CategoryListVO> categoryListVOList = new ArrayList<>();

        //每个category都是一个一级类目


        for (Category category : categories) {
            List<CategoryVO> categoryVOList = new ArrayList<>();
            CategoryListVO categoryListVO = new CategoryListVO();

            CategoryExample categoryExample1 = new CategoryExample();
            CategoryExample.Criteria criteria1 = categoryExample1.createCriteria();
            criteria1.andPidEqualTo(category.getId());
            List<Category> categories1 = categoryMapper.selectByExample(categoryExample1);

            //每个category是一个二级类目
            for (Category category1 : categories1) {

                CategoryVO categoryVO = new CategoryVO(category1.getId(), category1.getName(), category1.getKeywords(), category1.getDesc(), category1.getIconUrl(), category1.getPicUrl(), category1.getLevel());
                categoryVOList.add(categoryVO);
            }

            categoryListVO = new CategoryListVO(category.getId(), category.getName(), category.getKeywords(), category.getDesc(), category.getIconUrl(), category.getPicUrl(), category.getLevel(), categoryVOList);


            categoryListVOList.add(categoryListVO);
        }

        return categoryListVOList;
    }

    /**
     * @return
     * @author hdf
     * @description 查询类目L1
     */
    @Override
    public List<CategoryL1VO> selectL1Category() {
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andPidEqualTo(0);
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        List<CategoryL1VO> categoryL1VOList = new ArrayList<>();

        for (Category category : categories) {
            CategoryL1VO categoryL1VO = new CategoryL1VO(category.getId(), category.getName());
            categoryL1VOList.add(categoryL1VO);
        }
        return categoryL1VOList;
    }




    /**
     * @author hdf
     * @description 创建类目
     * @return
     */
    @Override
    public CategoryAddVO createCategory(CategoryAddBO categoryAddBO) {

        //插入添加的数据
        //如果添加重复类目，提示类目名称重复(先把数据库里面的一级类目搜索出来，比较)
        CategoryAddVO categoryAddVO = null;

        CategoryExample categoryExample1 = new CategoryExample();
        CategoryExample.Criteria criteria1 = categoryExample1.createCriteria();
        criteria1.andNameEqualTo(categoryAddBO.getName());
        List<Category> categories1 = categoryMapper.selectByExample(categoryExample1);
        if (categories1.size() != 0){
            return null;
        }



        Category category = new Category(null,categoryAddBO.getName(),categoryAddBO.getKeywords(),categoryAddBO.getDesc(),categoryAddBO.getPid(),categoryAddBO.getIconUrl(),categoryAddBO.getPicUrl(),categoryAddBO.getLevel(),null, new Date(),new Date(),null);
        categoryMapper.insertSelective(category);
        //查询添加的数据并且返回
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andPidEqualTo(categoryAddBO.getPid())
                .andPicUrlEqualTo(categoryAddBO.getPicUrl());
        List<Category> categories = categoryMapper.selectByExample(categoryExample);
        for (Category category1 : categories) {
            categoryAddVO = new CategoryAddVO(category1.getId(), category1.getName(), category1.getKeywords(), category1.getDesc(), category1.getPid(), category1.getIconUrl(), category1.getPicUrl(), category1.getLevel(), category1.getAddTime(), category1.getUpdateTime());
        }


        return categoryAddVO;
    }

    /**
     * @author hdf
     * @description 更新类目
     * @return
     */
    @Override
    public String updateL1Category(CategoryL1UpdateBO categoryL1UpdateBO) {


        // String status = "0";
        // CategoryExample categoryExample1 = new CategoryExample();
        // CategoryExample.Criteria criteria1 = categoryExample1.createCriteria();
        // criteria1.andLevelEqualTo("L1");
        // List<Category> categories1 = categoryMapper.selectByExample(categoryExample1);
        // if
        if (categoryL1UpdateBO.getPid() == null){
            Category category1 = new Category(categoryL1UpdateBO.getId(),categoryL1UpdateBO.getName(),categoryL1UpdateBO.getKeywords(),categoryL1UpdateBO.getDesc(),null,categoryL1UpdateBO.getIconUrl(),categoryL1UpdateBO.getPicUrl(),categoryL1UpdateBO.getLevel(),null,new Date(),new Date(),null);

            categoryMapper.updateByPrimaryKeySelective(category1);
        } else {
            Category category2 = new Category(categoryL1UpdateBO.getId(), categoryL1UpdateBO.getName(), categoryL1UpdateBO.getKeywords(), categoryL1UpdateBO.getDesc(), categoryL1UpdateBO.getPid(), categoryL1UpdateBO.getIconUrl(), categoryL1UpdateBO.getPicUrl(), categoryL1UpdateBO.getLevel(), null, new Date(), new Date(), null);

            categoryMapper.updateByPrimaryKeySelective(category2);
        }
        return "1";
    }

    /**
     * @author hdf
     * @description 删除类目
     * @return
     */
    @Override
    public void deleteCategory(CategoryL1UpdateBO categoryL1UpdateBO) {
        if (categoryL1UpdateBO.getPid() == null){
            Category category1 = new Category(categoryL1UpdateBO.getId(),categoryL1UpdateBO.getName(),categoryL1UpdateBO.getKeywords(),categoryL1UpdateBO.getDesc(),null,categoryL1UpdateBO.getIconUrl(),categoryL1UpdateBO.getPicUrl(),categoryL1UpdateBO.getLevel(),null,new Date(),new Date(),true);

            categoryMapper.deleteByPrimaryKey(category1.getId());
        } else {
            Category category2 = new Category(categoryL1UpdateBO.getId(), categoryL1UpdateBO.getName(), categoryL1UpdateBO.getKeywords(), categoryL1UpdateBO.getDesc(), categoryL1UpdateBO.getPid(), categoryL1UpdateBO.getIconUrl(), categoryL1UpdateBO.getPicUrl(), categoryL1UpdateBO.getLevel(), null, new Date(), new Date(), true);
            CategoryExample categoryExample = new CategoryExample();
            CategoryExample.Criteria criteria = categoryExample.createCriteria();
            criteria.andPidEqualTo(category2.getPid());
            categoryMapper.deleteByPrimaryKey(category2.getPid());
            categoryMapper.deleteByExample(categoryExample);
        }
    }


    /**
     * @return
     * @author ckd
     * @description 通用问题删除
     */
    @Override
    public void deleteIssue(int id) {

        IssueExample issueExample = new IssueExample();
        IssueExample.Criteria criteria = issueExample.createCriteria();
        Issue issue = new Issue();
        issue.setId(id);
        issue.setDeleted(true);
        issueMapper.updateByPrimaryKeySelective(issue);

    }

    /**
     * @return
     * @author ckd
     * @description 通用问题更新
     */
    @Override
    public UpdateIssueVO updateIssue(UpdateIssueBO updateIssueBO) {
        IssueExample issueExample = new IssueExample();
        IssueExample.Criteria criteria = issueExample.createCriteria();
        Issue issue = new Issue();
        issue.setId(updateIssueBO.getId());
        issue.setAddTime(updateIssueBO.getAddTime());
        issue.setAnswer(updateIssueBO.getAnswer());
        issue.setDeleted(updateIssueBO.isDeleted());
        issue.setQuestion(updateIssueBO.getQuestion());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        issue.setUpdateTime(new Date());
        issueMapper.updateByPrimaryKeySelective(issue);
        return new UpdateIssueVO(issue.getId(), issue.getQuestion(), issue.getAnswer(),
                issue.getAddTime(), issue.getUpdateTime(), issue.getDeleted());
    }


    /**
     * @return
     * @author ckd
     * @description 通用问题增加
     */
    @Override
    public CreatIssueVO createIssue(String answer, String question) {
        IssueExample issueExample = new IssueExample();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Issue issue = new Issue(null, question, answer, new Date(), new Date(), false);
        issueMapper.insert(issue);
        return new CreatIssueVO(issue.getAddTime(), question, issue.getId(), answer, issue.getUpdateTime());
    }

    /**
     * @author ckd
     * @description 关键词列表
     */
    @Override
    public KeywordListVO keywordList(Integer page, Integer limit, String sort, String order, String keyword, String url) {
        PageHelper.startPage(page, limit);
        KeywordExample keywordExample = new KeywordExample();
        KeywordExample.Criteria criteria = keywordExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (keyword != null) {
            criteria.andKeywordLike("%" + keyword + "%");
        }
        if (url != null) {
            criteria.andUrlLike("%" + url + "%");
        }
        keywordExample.setOrderByClause(sort + " " + order);
        List<KeyWordBean> keyWordBeans = new ArrayList<>();
        List<Keyword> keywords = keywordMapper.selectByExample(keywordExample);

        SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        for (Keyword keyword1 : keywords) {
            keyWordBeans.add(new KeyWordBean(keyword1.getId(), keyword1.getKeyword(), keyword1.getUrl(),
                    keyword1.getIsHot(), keyword1.getIsDefault(), keyword1.getSortOrder(),
                    sdf.format(keyword1.getAddTime()), sdf.format(keyword1.getUpdateTime()), keyword1.getDeleted()));
        }
        PageInfo<Keyword> keywordPageInfo = new PageInfo<>(keywords);
        int count = (int) keywordPageInfo.getTotal();
        return new KeywordListVO(count, keyWordBeans);
    }

    /**
     * @author ckd
     * @description 关键词列表增加
     */
    @Override
    public CreatKeyWordVO createKeyword(Boolean isDefault, Boolean isHot, String keyword, String url) {
        KeywordExample keywordExample = new KeywordExample();
        SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        Keyword keyword1 = new Keyword(null, keyword, url, isHot, isDefault, null, new Date(), new Date(), false);
        keywordMapper.insertSelective(keyword1);
        return new CreatKeyWordVO(keyword1.getId(), keyword, url, isHot, isDefault, keyword1.getAddTime().toString(), keyword1.getUpdateTime().toString());
    }

    /**
     * @author ckd
     * @description 关键词列表删除
     */
    @Override
    public void deleteKeyword(int id) {
        KeywordExample keywordExample = new KeywordExample();
        Keyword keyword = new Keyword();
        keyword.setId(id);
        keyword.setDeleted(true);
        keywordMapper.updateByPrimaryKeySelective(keyword);
    }

    /**
     * @author ckd
     * @description 关键词列表更新
     */
    @Override
    public UpdateKeywordVO updateKeyword(UpdateKeywordVO keyword) {
        KeywordExample keywordExample = new KeywordExample();
        SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Keyword keyword1 = new Keyword(keyword.getId(), keyword.getKeyword(), keyword.getUrl(), keyword.isIsHot(),
                keyword.isIsDefault(), keyword.getSortOrder(), sdf.parse(keyword.getAddTime(), pos),
                new Date(), keyword.isIsDefault());
        keywordMapper.updateByPrimaryKeySelective(keyword1);
        return null;
    }
    /**
     * @author 刘森飚
     * @description 获取订单列表
     */
    @Override
    public OrderListVo getOrderList(OrderListParamBo orderListParamBo) {

        OrderExample orderExample = new OrderExample();

        OrderExample.Criteria criteria = orderExample.createCriteria();
        if (orderListParamBo.getUserId() != null) {
            System.out.println("asdasdsaadasd" + orderListParamBo.getUserId());
            criteria.andUserIdEqualTo(orderListParamBo.getUserId());
        }
        if (orderListParamBo.getOrderSn() != null) {
            criteria.andOrderSnLike("%" + orderListParamBo.getOrderSn() + "%");
        }
        if (orderListParamBo.getOrder() != null) {
            orderExample.setOrderByClause(orderListParamBo.getSort() + " " + orderListParamBo.getOrder());
        }

        if (orderListParamBo.getOrderStatusArray() != null && orderListParamBo.getOrderStatusArray().length != 0) {
            Integer[] orderStatusArray = orderListParamBo.getOrderStatusArray();
            List<Short> shorts = new ArrayList<>();
            for (int i = 0; i < orderStatusArray.length; i++) {
                int s = orderStatusArray[i];
                shorts.add((short) s);
            }
            criteria.andOrderStatusIn(shorts);
        }

        PageHelper.startPage(orderListParamBo.getPage(), orderListParamBo.getLimit());
        List<Order> orders = orderMapper.selectByExample(orderExample);

        PageInfo<Order> orderPageInfo = new PageInfo<>(orders);

        List<OrderListVoForList> ordersVos = new ArrayList<>();

        for (Order order : orders) {
            OrderListVoForList orderListVoForList = new OrderListVoForList();
            orderListVoForList.setId(order.getId());
            orderListVoForList.setUserId(order.getUserId());
            orderListVoForList.setOrderSn(order.getOrderSn());
            orderListVoForList.setOrderStatus(order.getOrderStatus());
            orderListVoForList.setConsignee(order.getConsignee());
            orderListVoForList.setMobile(order.getMobile());
            orderListVoForList.setAddress(order.getAddress());
            orderListVoForList.setMessage(order.getMessage());
            orderListVoForList.setGoodsPrice(order.getGoodsPrice());
            orderListVoForList.setFreightPrice(order.getFreightPrice());
            orderListVoForList.setCouponPrice(order.getCouponPrice());
            orderListVoForList.setIntegralPrice(order.getIntegralPrice());
            orderListVoForList.setGrouponPrice(order.getGrouponPrice());
            orderListVoForList.setOrderPrice(order.getOrderPrice());
            orderListVoForList.setActualPrice(order.getActualPrice());
            orderListVoForList.setComments(order.getComments());
            orderListVoForList.setAddTime(order.getAddTime());
            orderListVoForList.setUpdateTime(order.getUpdateTime());
            orderListVoForList.setDeleted(order.getDeleted());
            orderListVoForList.setEndTime(order.getEndTime());
            orderListVoForList.setShipSn(order.getShipSn());
            orderListVoForList.setShipChannel(order.getShipChannel());
            orderListVoForList.setShipTime(order.getShipTime());

            ordersVos.add(orderListVoForList);
        }

        OrderListVo orderListVo = new OrderListVo();
        orderListVo.setItems(ordersVos);
        orderListVo.setTotal((int) orderPageInfo.getTotal());
        return orderListVo;
    }
    /**
     * @author 刘森飚
     * @description 获取订单详情
     */
    @Override
    public OrderDetailVo getOrderDetail(Integer id) {
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andIdEqualTo(id);
        List<Order> orders = orderMapper.selectByExample(orderExample);
        Order order = null;
        for (Order order1 : orders) {
            order = order1;
            break;
        }

        //根据order查询orderGoods
        OrderGoodsExample orderGoodsExample = new OrderGoodsExample();
        OrderGoodsExample.Criteria criteria1 = orderGoodsExample.createCriteria();
        criteria1.andOrderIdEqualTo(order.getId());
        List<OrderGoods> orderGoods = orderGoodsMapper.selectByExample(orderGoodsExample);

        //根据order.userid查user信息
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria2 = userExample.createCriteria();
        criteria2.andIdEqualTo(order.getUserId());
        List<User> users = userMapper.selectByExample(userExample);
        User user = null;
        for (User user1 : users) {
            user = user1;
            break;
        }


        OrderDetailVo orderDetailVo = new OrderDetailVo();

        orderDetailVo.setOrder(order);
        orderDetailVo.setOrderGoods(orderGoods);
        orderDetailVo.setUser(user);

        return orderDetailVo;
    }

    /**
     * @author 刘森飚
     * @description 订单发货
     */
    @Override
    public void giveAShip(OrderShipBO shipBO) {
        Order order = orderMapper.selectByPrimaryKey(shipBO.getOrderId());
        order.setShipChannel(shipBO.getShipChannel());
        order.setShipSn(shipBO.getShipSn());
        Date date = new Date();
        order.setUpdateTime(date);
        order.setShipTime(date);
        order.setOrderStatus((short) 301);
        orderMapper.updateByPrimaryKeySelective(order);
    }

}
